/*
   Copyright (c) 2019 Shanghai Xuanzi Technology Co. Ltd https://xuanzi.ltd
   XZMindMap is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details.

*/

package xuanzi.openmind.nodes;

import xuanzi.commons.graphics.Canvas;
import xuanzi.commons.graphics.Path;
import xuanzi.openmind.layout.Box;

public class Summary extends Widget{
	
	Node a,b;
	
	float borderSize = 5f;
	
	public Summary(Node a,Node b) {
		this.a = a;
		this.b = b;
		label = "概 要"; 
	}
	
	public Summary() {
		label = "概 要";
	}
	
	
	@Override
	public void draw(Canvas canvas) { 
		super.draw(canvas); 
		{
			setEmpty();
			union(a.getNodeBound());
			union(b.getNodeBound());
			union(a.renderBuffer.childBound);
			union(b.renderBuffer.childBound);
		}{
			paint.stroke(a.renderBuffer.borderColor,borderSize);
			float endline = a.renderBuffer.align == Box.ALIGN_END?right:left; 
			path.reset();
			{
				path.moveTo(right, centerY());
				path.cubicTo(right-50, centerY(), right, top, right-50, top);
			}{
				path.moveTo(right, centerY());
				path.cubicTo(right-50, centerY(), right, bottom, right-50, bottom);
			}
			canvas.drawPath(path, paint);
			paint.fill(a.renderBuffer.textColor);
			paint.textAlign = 2;
			canvas.drawText(label, right, centerY(), paint);
		}
	}
	
	Path path = new Path();
	
	
	
	@Override
	public void onLayout(Box parent) {
		setEmpty();
		union(a.getNodeBound());
		union(b.getNodeBound());
		union(a.renderBuffer.childBound);
		union(b.renderBuffer.childBound);
		super.onLayout(parent);
		System.out.println("layout "+this);
	}
	
	public void setA(Node a) {
		this.a = a;
	}
	
	public void setB(Node b) {
		this.b = b;
	}
	
	public Node getA() {
		return a;
	}
	
	public Node getB() {
		return b;
	}

}
